#!/bin/bash

# 获取当前时间戳
current_time=$(date +"%Y%m%d.%H.%M.%S")

# 创建备份目录
backup_dir="/mnt/hdd/backup/${current_time}"
mkdir -p "${backup_dir}"

# # 创建桌面备份目录
# backup_desktop_dir="${backup_dir}/Desktop"
# mkdir -p "${backup_desktop_dir}"

# # 桌面目录路径
# desktop_dir=~/Desktop

# # 函数：判断是否为项目文件夹
# is_project_folder() {
#     local dir="$1"
#     [[ -d "$dir/node_modules" || -d "$dir/build" || -d "$dir/myenv" ]]
# }

# # 遍历桌面目录下的所有文件和文件夹
# for item in "${desktop_dir}"/*; do
#     # 获取项目名称
#     item_name=$(basename "${item}")
    
#     # 如果是文件，直接复制
#     if [ -f "${item}" ]; then
#         cp "${item}" "${backup_desktop_dir}/${item_name}"
#     elif [ -d "${item}" ]; then
#         # 如果是文件夹，判断是否是项目文件夹
#         if is_project_folder "$item"; then
#             # 是项目文件夹，复制时排除node_modules
#             mkdir -p "${backup_desktop_dir}/${item_name}"
#             rsync -av --exclude='node_modules' --exclude='build' --exclude='myenv' "${item}/" "${backup_desktop_dir}/${item_name}/"
#         else
#             # 不是项目文件夹，直接复制整个文件夹
#             cp -r "${item}" "${backup_desktop_dir}/${item_name}"
#         fi
#     fi
# done

# # 备份植物大战僵尸游戏存档
# backup_PopCap_Games_dir="${backup_dir}/.deepinwine/com.popcap.plantsvszombies.deepin/drive_c/ProgramData"
# mkdir -p "${backup_PopCap_Games_dir}"
# cp -r "/home/zhang/.deepinwine/com.popcap.plantsvszombies.deepin/drive_c/ProgramData/PopCap Games" "${backup_PopCap_Games_dir}"

# 备份.ssh
cp -r ~/.ssh "${backup_dir}/.ssh"

# 备份.snipaste
backup_snipaste_dir="${backup_dir}/.snipaste"
mkdir -p "${backup_snipaste_dir}"
cp -r ~/.snipaste/config.ini "${backup_snipaste_dir}/config.ini"

# 备份opt
backup_opt_dir="${backup_dir}/opt"
mkdir -p "${backup_opt_dir}"
cp -r "/opt/Chatbox" "${backup_opt_dir}/Chatbox"
cp -r "/opt/Godot" "${backup_opt_dir}/Godot"
cp -r "/opt/Snipaste" "${backup_opt_dir}/Snipaste"

# 备份/usr/local/bin
backup_usr_local_bin_dir="${backup_dir}/usr/local"
mkdir -p "${backup_usr_local_bin_dir}"
cp -r "/usr/local/bin" "${backup_usr_local_bin_dir}"

# 备份/etc/hosts
backup_etc_dir="${backup_dir}/etc"
mkdir -p "${backup_etc_dir}"
cp "/etc/hosts" "${backup_etc_dir}/hosts"

# 备份/etc/openvpn/client
backup_etc_openvpn_client_dir="${backup_dir}/etc/openvpn"
mkdir -p "${backup_etc_openvpn_client_dir}"
cp -r "/etc/openvpn/client" "${backup_etc_openvpn_client_dir}"

# 备份/usr/share/applications
backup_usr_share_applications_dir="${backup_dir}/usr/share/applications"
mkdir -p "${backup_usr_share_applications_dir}"
cp "/usr/share/applications/Chatbox.desktop" "${backup_usr_share_applications_dir}/Chatbox.desktop"
cp "/usr/share/applications/Postman.desktop" "${backup_usr_share_applications_dir}/Postman.desktop"
cp "/usr/share/applications/Godot.desktop" "${backup_usr_share_applications_dir}/Godot.desktop"
cp "/usr/share/applications/OpenVPN.desktop" "${backup_usr_share_applications_dir}/OpenVPN.desktop"
cp "/usr/share/applications/Snipaste.desktop" "${backup_usr_share_applications_dir}/Snipaste.desktop"

# 备份/usr/share/deepin/dde-file-manager/oem-menuextensions
backup_oem_menuextensions_dir="${backup_dir}/usr/share/deepin/dde-file-manager"
mkdir -p "${backup_oem_menuextensions_dir}"
cp -r "/usr/share/deepin/dde-file-manager/oem-menuextensions" "${backup_oem_menuextensions_dir}"

echo "备份完成，备份目录为：${backup_dir}"
